import { Column, Entity, Index, JoinColumn, ManyToOne, OneToOne } from "typeorm";
import {CommonEntity} from "~/common/entity/common.entity";
import { UserEntity } from "../user/user.entity";
import { HouseEntity } from "../assess/house/house.entity"

/**
 * 分享内容
 */
@Index(["id"])
@Entity({name: "share-content"})
export class ShareContentEntity extends CommonEntity {
	// 标题、描述、封面、链接、关联用户ID
	@Column({type: "text", comment: "标题"})
  title: string;

	@Column({type: "text", comment: "描述"})
	description: string;

	@Column({type: "text", comment: "封面"})
	cover: string;

	@Column({type: "text", comment: "链接"})
	link: string;

	// TODO 分享类型，如：房产评估、首页、书城、商城、咨询
	// TODO 分享类型扩展参数 JSON字符串

	/**
	 * 关联房产评估
	 */
	@OneToOne(() => HouseEntity, { eager: true }) // eager: true 表示在查询时立即加载
	@JoinColumn({ name: "houseId" }) // 关联字段
	house: HouseEntity;

	/**
	 * 关联分享用户
	 */
	@ManyToOne(() => UserEntity, user => user.shareContents) // 多对一关联
	@JoinColumn({ name: "userId" }) // 关联字段
  user: UserEntity;
}